var dataJson = [];
$(function(){
	$("#clothingType").combobox({
		data:clothingType,
		valueField:'id',  
		textField:'text',
	})
	$("#addstatus,#editstatus").combobox({
		data:leaseType,
		valueField:'id',  
		textField:'text',
		editable:false
	})
	loadData();
	$("#leaseDatagrid").datagrid({
		data:dataJson,
	    fit:true,
	    toolbar:'#leaseTolbar',
	    fitColumns:true,
	    rownumbers:true,
	    singleSelect:true,
	    columns:[[  
	            {field:'leaseId',hidden:true,title:'租赁ID',width:100,align:"center"},
	            {field:'userName',title:'客户名称',width:100,align:"center"}, 
		        {field:'idCard',title:'身份证',width:100,align:"center"}, 
		        {field:'clothingName',title:'服装名称',width:100,align:"center"}, 
		        {field:'clothingType',title:'服装类型',width:100,align:"center",
		        	formatter:function(value,row,index){
		        		return typeToName(value,clothingType);
		        	}	}, 
	  	        {field:'clothingRent',title:'服装租金',width:100,align:"center"}, 
	  	        {field:'foregift',title:'押金',width:100,align:"center"}, 
	  	        {field:'status',title:'租赁状态',width:100,align:"center",
	  	        	formatter:function(value,row,index){
		        		return typeToName(value,leaseType);
		        	}
	  	        	}, 
	  	        {field:'returnCount',title:'归还数量',width:100,align:"center"}, 
	  	        {field:'leaseTime',title:'租赁时间',width:100,align:"center"}, 
	  	        {field:'returnTime',title:'归还时间',width:100,align:"center",}, 
	  	        {field:'operation',title:'操作',width:100,align:"center",
	        	formatter:function(value,row,index){
	        		return  " <a  href='#' onclick=delRow('"+row.leaseId+"'); >删除</a> ";
	        	}
	        	
	        },
	    ]]  
	
	});
	
	
})
function loadData(){
	$.ajax({
		url:$WEB_ROOT_PATH+"/Return/getAllReturn.json",
		type:"post",
		async: false, 
		data: JSON.stringify({"clothingName":'',"clothingType":'',"returnTime":'',"leaseTime":''}),
		contentType: "application/json",
		dataType:"json",
		success:function(result){
			dataJson = result.data.returnInfoList;
		}
	})
}
function delRow(id){
	 $.messager.confirm("操作提示", "您确定要删除吗？", function (data) {  
         if (data) {  
			$.ajax({
				url:$WEB_ROOT_PATH+"/Lease/deleteLeaseById.json",
				type:"post",
				async: false, 
				data: JSON.stringify({"leaseId":id}),
				contentType: "application/json",
				dataType:"json",
				success:function(result){
					if(result.data.success == "0"){
						$.messager.alert("信息", "删除成功！",'info'); 
					}else{
						$.messager.alert("信息", "删除失败！",'info'); 
					}
					loadData();
					$("#leaseDatagrid").datagrid("loadData",dataJson);
				}
			})
		} else {  
		    return;  
		 }  
	 }); 
}

function doSearch(){
	$.ajax({
		url:$WEB_ROOT_PATH+"/Return/getAllReturn.json",
		type:"post",
		async: false, 
		data: JSON.stringify({"clothingName":$("#clothingName").val(),"clothingType":$("#clothingType").combobox("getValue"),"returnTime":$("#returnTime").datebox("getValue"),"leaseTime":$("#leaseTime").datebox("getValue")}),
		contentType: "application/json",
		dataType:"json",
		success:function(result){
			if(result.data.returnInfoList == undefined && result.data.returnInfoList==null){
				dataJson = [];
			}else{
				dataJson = result.data.returnInfoList;
			}
			$("#leaseDatagrid").datagrid("loadData",dataJson);
		}
	})
}